<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/15
 * Time: 13:54
 */

namespace app\admin\controller;

\think\Loader::import('controller/Controller', \think\Config::get('traits_path'), EXT);
use app\admin\Controller;
use app\common\model\StickPay as modelSp;

class StickPay extends  Controller
{
    use \app\admin\traits\controller\Controller;
    public function index () {
        $where = [
            'sp.isdelete' => 0
        ];
        $keyword = $this->request->param('keyword');

        $listRows = 20;
        $filed = "sp.*,su.name, su.head,su.phone";
        $model = new modelSp();
        $list = $model->getStickPayList($where, $filed, $listRows, $this->request, $keyword);

        $this->view->assign('list', $list);
        $this->view->assign("count", $list->total());
        $this->view->assign("page", $list->render());
        $this->view->assign('numPerPage', $list->listRows());

        return $this->view->fetch();

        return $this->view->fetch();
    }

    public function forbid() {

        if ($this->request->method() == "GET") {

            $id = $this->request->param('id', '');
            $where = [
                'id' => $id,
                'isdelete' => 0
            ];
            $data = [
                'status' => 0
            ];

            $model = new modelSp();
            $res = $model->updateStatus($where, $data);

            if ($res) {
                ajax_return_adv('恢复数据成功');
            } else{
                ajax_return_adv_error('恢复数据失败');
            }
        }
    }

    /**
     * 默认恢复操作
     */
    public function resume(){

        if ($this->request->method() == "GET") {

            $id = $this->request->param('id', '');
            $where = [
                'id' => $id,
                'isdelete' => 0
            ];
            $data = [
                'status' => 1
            ];

            $model = new modelSp();
            $res = $model->updateStatus($where, $data);

            if ($res) {
                ajax_return_adv('恢复数据成功');
            } else{
                ajax_return_adv_error('恢复数据失败');
            }
        }
    }

}